package fr.imag.wifibot.master;

import java.io.PrintWriter;
import java.util.logging.*;

public class MasterService implements IMasterService {
	private static PrintWriter out;
	
	public static Logger logger;

	static {
	    try {
	    	int limit = 1000000;
	    	int numLogFiles = 100;
	    	boolean append = true;
		      FileHandler fh = new FileHandler("wifibot.log", limit, numLogFiles, append);
		      //fh.setFormatter(new XMLFormatter());
		      fh.setFormatter(new SimpleFormatter());
		      logger = Logger.getLogger("TestLog");
		      logger.addHandler(fh);
	    }
	    catch (Exception e) {
	    	e.printStackTrace();
	    }
	}
	
	public MasterService(PrintWriter out) {
		this.out = out;
	}

	public void incomingMessage(String msg) {
		if(out != null) {
			out.println(msg);
			out.flush();
			logger.info(msg);
		}
	}
	
	public void setOut(PrintWriter out) {
		MasterService.out = out;
	}

}
